# Format for detection
# using class like a struct
# and detect class objects
import struct

# Example
class FMT_OZIP(object):
    def __init__(self):
        self.mode = "bin"                  # if this set "ext" will detect file ext, if this set "bin", will read file
        self.offset = 0                    # Magic start offset if this is -1, will auto detect 8192 bytes of start
        # self.bufsize = 8192              # if offset = -1 then use this
        self.structstr = "16s16s48s"       # 16 bytes 16bytes 48 bytes
        self.magic = b'OPPOENCRYPT!'       # Magic
        self.retfmt = "ozip"               # return format strings
    
    def readinfo(self, buf, verbose=False): # verbose is show to console detial information
        (
            magic,
            size,
            sha1
        ) = struct.unpack(self.structstr, buf)
        if magic.rstrip(b'\x00') == self.magic:
            if verbose:
                print("Full information")
                print("\tOZIP ENCRYPTED DATA SIZE : ", size.decode('ASCII'))
                print("\tOZIP sha1 checksum : ", sha1.decode('ASCII'))
            return self.retfmt
        else:
            return

class FMT_SDAT(object):
    def __init__(self):
        self.mode = "ext"
        self.ext = ".new.dat"               # detect file ext        
        # self.offset = 0                
        # self.structstr = "16s16s48s"   
        # self.magic = b'OPPOENCRYPT!'   
        self.retfmt = "sdat"
        # if detect ext then no need defined a readinfo

class FMT_BR(object):
    def __init__(self):
        self.mode = "ext"
        self.ext = ".br"
        self.retfmt = "br"
